﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace _Ajax上传文件解析.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }


        public ActionResult UpLoadExcel()
        {
            return View();
        }

        public ActionResult UpLoadImg()
        {
            return View();
        }

        public ActionResult UpLoadFilesExcel()
        {
            HttpPostedFileBase files = Request.Files["MyFiles"];
            if (files != null)
            {
                string ParentPath = Server.MapPath("~/LoadFiles/Excels/");
                string FilePath = DateTime.Now.ToString("yyyyMMddHHmmssffff") + "_" + files.FileName;
                files.SaveAs(ParentPath + FilePath);

                DataTable dt_1 = ExcelUtil.AnalysisExcel2007(ParentPath + FilePath);

                return Json(new { status = "true", msg = "失败!" }, JsonRequestBehavior.AllowGet);
            }
            return Json(new { status = "false", msg = "失败!" }, JsonRequestBehavior.AllowGet);

        }

        public ActionResult UpLoadFilesImg()
        {
            return View();
        }



        public void DownExcel()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("姓名", typeof(string));
            dt.Columns.Add("年龄", typeof(int));

            DataRow dr = dt.NewRow();
            dr["姓名"] = "小明";
            dr["年龄"] = 18;

            dt.Rows.Add(dr);

            //ExcelUtil.DownLoadExcelByDataTable(dt,,"Sheet1");
        }
    }
}